var t = getApp();

Page({
    data: {
        order_pay_id: "",
        bank: [],
        payer_name: "",
        payer_phone: "",
        id_no: "",
        cvv: "",
        date: "2016-06",
        card_no: "",
        bank_name: "",
        bank_type: "",
        id_type: "",
        user_agrt: "",
        checked: !0,
        show2: !1,
        show3: !1,
        show4: !1,
        show5: !1,
        radio: "",
        radio1: "",
        radio2: "",
        idType: [ {
            id: "1",
            text: "身份证"
        }, {
            id: "2",
            text: "军官证"
        }, {
            id: "3",
            text: "士兵证"
        }, {
            id: "4",
            text: "护照"
        }, {
            id: "5",
            text: "港澳台居民往来通行证"
        }, {
            id: "6",
            text: "临时身份证"
        }, {
            id: "7",
            text: "户口本"
        }, {
            id: "8",
            text: "警官证"
        }, {
            id: "9",
            text: "外国人永久居留证"
        }, {
            id: "10",
            text: "其他"
        }, {
            id: "11",
            text: "外国护照"
        }, {
            id: "12",
            text: "营业执照"
        } ],
        card: [ {
            id: "0",
            text: "储蓄卡"
        }, {
            id: "1",
            text: "信用卡"
        } ],
        datas: [ {
            id: "1",
            text: "中国工商银行"
        }, {
            id: "2",
            text: "中国银行"
        }, {
            id: "3",
            text: "中信银行"
        }, {
            id: "4",
            text: "上海银行"
        }, {
            id: "5",
            text: "中国建设银行"
        }, {
            id: "6",
            text: "光大银行"
        }, {
            id: "7",
            text: "民生银行"
        }, {
            id: "8",
            text: "北京银行"
        }, {
            id: "9",
            text: "平安银行"
        }, {
            id: "10",
            text: "交通银行"
        }, {
            id: "11",
            text: "招商银行"
        }, {
            id: "12",
            text: "广发银行"
        }, {
            id: "13",
            text: "浦发银行"
        }, {
            id: "14",
            text: "邮政银行"
        } ],
        status: "",
        count: "",
        check_open: !1,
        isOpenCaptcha: !1,
        captcha: "",
        imgCodeLink: "",
        member_phone: "",
        v2_code: ""
    },
    onLoad: function(t) {
        this.getMemberPhone(), this.initData();
        var a = t;
        this.setData({
            card_no: a.card_no,
            order_pay_id: a.order_pay_id
        }), t.status && this.setData({
            status: t.status
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    nameInp: function(t) {
        var a = t.detail.value;
        this.setData({
            payer_name: a
        });
    },
    phoneInp: function(t) {
        var a = t.detail.value;
        this.setData({
            payer_phone: a
        });
    },
    idInp: function(t) {
        var a = t.detail.value;
        this.setData({
            id_no: a
        });
    },
    cvvInp: function(t) {
        var a = t.detail.value;
        this.setData({
            cvv: a
        });
    },
    bindDateChange: function(t) {
        this.setData({
            date: t.detail.value
        });
    },
    openBank: function() {
        this.setData({
            show2: !0
        });
    },
    closeBank: function() {
        this.setData({
            show2: !1
        });
    },
    openCard: function() {
        this.setData({
            show3: !0
        });
    },
    closeCard: function() {
        this.setData({
            show3: !1
        });
    },
    openType: function() {
        this.setData({
            show4: !0
        });
    },
    closeType: function() {
        this.setData({
            show4: !1
        });
    },
    bankChange: function(t) {
        var a = t.detail;
        this.setData({
            radio: a
        });
    },
    cardChange: function(t) {
        var a = t.detail;
        this.setData({
            radio1: a
        });
    },
    idChange: function(t) {
        var a = t.detail;
        this.setData({
            radio2: a
        });
    },
    openAgg: function() {
        this.setData({
            show5: !0
        });
    },
    closeAgg: function() {
        this.setData({
            show5: !1
        });
    },
    confirm: function() {
        var t = this;
        this.setData({
            show2: !1
        }), this.data.datas.forEach(function(a, e, i) {
            a.id == t.data.radio && t.setData({
                bank_name: a.text
            });
        });
    },
    cardConfirm: function() {
        var t = this;
        this.setData({
            show3: !1
        }), this.data.card.forEach(function(a, e, i) {
            a.id == t.data.radio1 && t.setData({
                bank_type: a.text
            });
        });
    },
    typeConfirm: function() {
        var t = this;
        this.setData({
            show4: !1
        }), this.data.idType.forEach(function(a, e, i) {
            a.id == t.data.radio2 && t.setData({
                id_type: a.text
            });
        });
    },
    toSelect: function(t) {
        this.setData({
            checked: t.detail
        });
    },
    initData: function() {
        this.setData({
            bank: [],
            payer_name: "",
            payer_phone: "",
            id_no: "",
            cvv: "",
            date: "2016-06",
            card_no: "",
            bank_name: "",
            bank_type: "",
            id_type: "",
            user_agrt: "",
            checked: !0,
            show2: !1,
            show3: !1,
            show4: !1,
            show5: !1,
            radio: "",
            radio1: "",
            radio2: "",
            idType: [ {
                id: "1",
                text: "身份证"
            }, {
                id: "2",
                text: "军官证"
            }, {
                id: "3",
                text: "士兵证"
            }, {
                id: "4",
                text: "护照"
            }, {
                id: "5",
                text: "港澳台居民往来通行证"
            }, {
                id: "6",
                text: "临时身份证"
            }, {
                id: "7",
                text: "户口本"
            }, {
                id: "8",
                text: "警官证"
            }, {
                id: "9",
                text: "外国人永久居留证"
            }, {
                id: "10",
                text: "其他"
            }, {
                id: "11",
                text: "外国护照"
            }, {
                id: "12",
                text: "营业执照"
            } ],
            card: [ {
                id: "0",
                text: "储蓄卡"
            }, {
                id: "1",
                text: "信用卡"
            } ],
            datas: [ {
                id: "1",
                text: "中国工商银行"
            }, {
                id: "2",
                text: "中国银行"
            }, {
                id: "3",
                text: "中信银行"
            }, {
                id: "4",
                text: "上海银行"
            }, {
                id: "5",
                text: "中国建设银行"
            }, {
                id: "6",
                text: "光大银行"
            }, {
                id: "7",
                text: "民生银行"
            }, {
                id: "8",
                text: "北京银行"
            }, {
                id: "9",
                text: "平安银行"
            }, {
                id: "10",
                text: "交通银行"
            }, {
                id: "11",
                text: "招商银行"
            }, {
                id: "12",
                text: "广发银行"
            }, {
                id: "13",
                text: "浦发银行"
            }, {
                id: "14",
                text: "邮政银行"
            } ]
        });
    },
    getBank: function() {
        var a = this, e = t.getNetAddresss("plugin.converge_pay.frontend.controllers.quick-pay-bank-card.index");
        t._getNetWork({
            url: e,
            showToastIn: !1,
            success: function(t) {
                var e = t.data;
                e.result, a.setData({
                    bank: e.data
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    getInfo: function() {
        var a = this, e = t.getNetAddresss("plugin.converge_pay.frontend.controllers.quick-pay-bank-card.get-payer-info");
        t._getNetWork({
            url: e,
            showToastIn: !1,
            success: function(t) {
                var e = t.data;
                1 == e.result && e.data && a.setData({
                    payer_name: e.data.payer_name,
                    radio2: e.data.id_type,
                    id_no: e.data.id_no
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    shijian: function() {
        var t = this.data.date.split("-")[0], a = this.data.date.split("-")[1];
        return "".concat(t, "/").concat(a);
    },
    getType: function(a) {
        var e = this, i = t.getNetAddresss("plugin.converge_pay.frontend.controllers.quick-pay-bank-card.get-pay-type");
        t._getNetWork({
            url: i,
            showToastIn: !1,
            success: function(t) {
                var i = t.data;
                1 == i.result ? 1 == i.data.pay_type ? wx.navigateTo({
                    url: "/packageD/quickPay/choose_bank/choose_bank?order_pay_id=" + e.data.order_pay_id + "&status=" + e.data.status
                }) : wx.navigateTo({
                    url: "/packageD/quickPay/bind_bank/bind_bank?card_id=" + a + "&order_pay_id=" + e.data.order_pay_id + "&status=" + e.data.status
                }) : wx.showToast({
                    icon: "none",
                    title: i.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    getAgrement: function() {
        var a = this, e = t.getNetAddresss("plugin.converge_pay.frontend.controllers.quick-pay-bank-card.get-user-agrt");
        t._getNetWork({
            url: e,
            showToastIn: !1,
            success: function(t) {
                var e = t.data;
                1 == e.result ? a.setData({
                    user_agrt: e.data.user_agrt
                }) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    addBank: function() {
        if (t._isTextEmpty(this.data.bank_name)) this.Toast("请选择所属银行"); else if (t._isTextEmpty(this.data.radio1)) this.Toast("请选择银行卡类型"); else if (t._isTextEmpty(this.data.date) && "1" == this.data.radio1) this.Toast("请选择信用卡有效期"); else if (t._isTextEmpty(this.data.cvv) && "1" == this.data.radio1) this.Toast("请填写安全码"); else if (t._isTextEmpty(this.data.payer_name)) this.Toast("请输入持卡人姓名"); else if (t._isTextEmpty(this.data.payer_phone)) this.Toast("请输入银行预留手机号"); else if (1 == this.data.check_open && t._isTextEmpty(this.data.member_phone)) this.Toast("请输入绑定手机号"); else if (1 == this.data.check_open && t._isTextEmpty(this.data.v2_code)) this.Toast("请输入验证码"); else if (t._isTextEmpty(this.data.checked)) this.Toast("请同意用户协议"); else {
            var a;
            "0" == this.data.radio1 ? a = {
                card_no: this.data.card_no,
                payer_name: this.data.payer_name,
                payer_phone: this.data.payer_phone,
                id_no: this.data.id_no,
                id_type: this.data.radio2,
                bank_type: this.data.radio1,
                bank_name: this.data.bank_name
            } : "1" == this.data.radio1 && (a = {
                card_no: this.data.card_no,
                payer_name: this.data.payer_name,
                payer_phone: this.data.payer_phone,
                id_no: this.data.id_no,
                id_type: this.data.radio2,
                bank_type: this.data.radio1,
                bank_name: this.data.bank_name,
                expire_date: this.shijian(this.data.date),
                cvv: this.data.cvv
            }), 1 == this.data.check_open && (a.code = this.data.v2_code);
            var e = this, i = t.getNetAddresss("plugin.converge_pay.frontend.controllers.quick-pay-bank-card.create");
            t._postNetWork({
                url: i,
                showToastIn: !1,
                data: {
                    data: a
                },
                success: function(t) {
                    var a = t.data;
                    1 == a.result ? e.getType(a.data.id) : wx.showToast({
                        icon: "none",
                        title: a.msg,
                        duration: 1500
                    });
                },
                fail: function(t) {
                    console.log(t.msg);
                }
            });
        }
    },
    getMemberPhone: function() {
        var a = this, e = this, i = t.getNetAddresss("plugin.converge_pay.frontend.controllers.quick-pay-bank-card.get-mobile");
        t._getNetWork({
            url: i,
            showToastIn: !1,
            success: function(t) {
                var i = t.data;
                1 === i.result ? (a.setData({
                    check_open: i.data.sms_check_open
                }), i.data.get_captcha && i.data.get_captcha.captcha && a.setData({
                    imgCodeLink: i.data.get_captcha.captcha.img,
                    isOpenCaptcha: i.data.get_captcha.captcha.status
                }), i.data.mobile ? (e.setData({
                    member_phone: i.data.mobile
                }), e.getAgrement(), e.getInfo(), e.getBank()) : wx.showModal({
                    title: "提示",
                    content: "商城会员没有绑定手机号，请绑定手机号",
                    success: function(t) {
                        t.confirm ? wx.navigateTo({
                            url: "/packageA/member/editmobile/editmobile"
                        }) : t.cancel && wx.navigateBack({
                            delta: 1
                        });
                    }
                })) : wx.showToast({
                    icon: "none",
                    title: i.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    memberPhoneInp: function(t) {
        var a = t.detail.value;
        this.setData({
            member_phone: a
        });
    },
    changeCaptcha: function(t) {
        var a = t.detail.value;
        this.setData({
            captcha: a
        });
    },
    v2CodeInp: function(t) {
        var a = t.detail.value;
        this.setData({
            v2_code: a
        });
    },
    getCaptchaImg: function() {
        var a = this, e = t.getNetAddresss("plugin.converge_pay.frontend.controllers.quick-pay-bank-card.get-mobile");
        t._getNetWork({
            url: e,
            data: {},
            success: function(e) {
                var i = e.data;
                1 !== i.result && t.tips(i.msg), i.data.get_captcha && i.data.get_captcha.captcha && a.setData({
                    imgCodeLink: i.data.get_captcha.captcha.img
                });
            }
        });
    },
    VerificationCode: function() {
        if (1 == this.data.isOpenCaptcha && t._isTextEmpty(this.data.captcha)) t.tips("请填写图形验证码"); else if (t._isTextEmpty(this.data.member_phone)) t.tips("请填写需要绑定的手机号"); else {
            wx.showLoading({
                title: "发送中"
            });
            var a = this, e = t.getNetAddresss("plugin.converge_pay.frontend.controllers.quick-pay-bank-card.send-code");
            t._getNetWork({
                showToastIn: !1,
                url: e,
                data: {
                    captcha: this.data.captcha
                },
                success: function(e) {
                    var i = e.data;
                    wx.hideLoading(), 1 == i.result ? a.getCode() : t.tips(i.msg);
                },
                fail: function(t) {}
            });
        }
    },
    getCode: function() {
        var t = this;
        this.data.timer || (this.data.count = 60, this.data.timer = setInterval(function() {
            t.data.count > 0 && t.data.count <= 60 ? (t.data.count--, t.setData({
                count: t.data.count
            })) : (clearInterval(t.timer), t.data.count = 0, t.data.timer = null, t.setData({
                count: t.data.count,
                timer: t.data.timer
            }));
        }, 1e3));
    }
});